// <reference path="jquery-1.3.2-vsdoc.js" />
var EvoStock = function() {
    var row, rowId, tableRow;
    return {
        init: function() {
            $('#modify').click(function() {
                $('#toolbar').toggle();
            });

            EvoStock.refreshMarkets();
        },

        refreshMarkets: function() {
            var indicators = ['up', 'down', 'ceiling', 'floor', 'freeze'];
            $.ajax({
                type: 'GET',
                url: 'Mobile/MarketInfo',
                success: function(value) {
                    var data = [];
                    eval('data = ' + value);
                    for (var i = 0; i < data.length; i++) {
                        row = data[i];
                        rowId = 'mr' + row.SB.toUpperCase();
                        tableRow = document.getElementById(rowId);
                        if (tableRow) {
                            tableRow.className = indicators[row.CT];
                            $(tableRow).empty().append('<td class="symbol">' + row.SB + '</td><td class="price">' + row.P + '</td><td class="change">' + row.C + '%</td>');
                        } else {
                            $('#symbols').append('<tr id="' + rowId + '" class="' + indicators[row.CT] + '"><td class="symbol">' + row.SB + '</td><td class="price">' + row.P + '</td><td class="change">' + row.C + '%</td></tr>');
                        }
                    }

                    setTimeout(EvoStock.refreshMarkets, 5000);
                }
            });
        },

        refreshPorfilios: function() {

        }
    };
} ();

$(document).ready(EvoStock.init);
    